﻿<%@ Application Language="C#" %>
<%@ Import Namespace="nplJobsWebSite" %>
<%@ Import Namespace="System.Web.Optimization" %>
<%@ Import Namespace="System.Web" %>


<script RunAt="server">

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        AuthConfig.RegisterOpenAuth();
        nplJobs.DB.Utility.strDBConnectionString = GetConnectionString;
        nplJobs.DB.Utility.strDBProvider = DBProvider;
    }

    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown      
        
    }

    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs
    }

    void Session_Start(object sender, EventArgs e)
    {
    }

    void Session_End(object sender, EventArgs e)
    {
        Session.Clear();
        Session.Abandon();
        Session.RemoveAll();
    }
    protected void Application_EndRequest()
    {
        var context = new HttpContextWrapper(this.Context);

        // If we're an ajax request and forms authentication caused a 302,
        // then we actually need to do a 401
        if (FormsAuthentication.IsEnabled && context.Response.StatusCode == 302
        && context.Request.Headers["X-Requested-With"] == "XMLHttpRequest")
        {
            context.Response.Clear();
            context.Response.StatusCode = 401;
        }
    } 
    


    public string GetConnectionString
    {
        get
        {
            string con = System.Configuration.ConfigurationManager.ConnectionStrings["SqlConnection"] != null ? System.Configuration.ConfigurationManager.ConnectionStrings["SqlConnection"].ToString() : string.Empty;
            return con;
        }

    }

    public string DBProvider
    {
        get
        {
            return "SQLSERVER";
        }
    }

</script>
